//index.js
//获取应用实例
const app = getApp()
Page({
     data: {
          list: [],//列表
          page: 1,//页数
     },
     onLoad: function () {
          var that = this
          that.setData({
               hidden: false
          })
          //     首页加载
          that.request()   
     },
     /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
     onReachBottom: function () {
          var that = this
          var page = that.data.page
          page++
          that.setData({
               page: page
          })
           //     首页分页加载
          that.request()
     },
     // 分享
     onShareAppMessage: function (res) {
          if (res.from === 'button') {
               // 来自页面内转发按钮
              // console.log(res.target)
          }
          return {
               title: '戏曲-京剧，秦腔，曲剧，晋剧',
               path: '/pages/index/index',
               success: function (res) {
                    //console.log(res)
                    wx.showToast({
                         title: '发送成功',
                         icon: 'none'
                    })
               },
               fail: function (res) {
                    // 转发失败
                    wx.showToast({
                         title: '发送失败',
                         icon: 'none'
                    })
               }
          }
     },
     //   请求
     request: function () {
          var that = this
          var page = that.data.page
          wx.request({
               url: app.data.apiurl + '/qupu/qupuList',
               dataType: 'json',
               method: "get",
               data: {
                    pageIndex: page,
                    pageSize:12
               },
               header: {
                    'content-type': 'application/json' // 默认值
               },
               success: function (res) {
                    var reslist = res.data.data
                    var list = that.data.list;
                    if (reslist.length==0){
                         wx.showToast({
                              title: '没有数据了...',
                              icon: 'none',
                              duration: 2000
                         }) 
                    }else{
                         for (var i = 0; i < reslist.length; i++) {
                              list.push(reslist[i]);
                         }
                         //console.log(list)
                         that.setData({
                              list: list,
                              hidden: true
                         }) 
                    }
               }
          })
     },
})
